package cn.tedu.mall.search.controller; 
 /*
 @Time: 2023/2/27 22:53
 @Author:GShuai
 @File:SearchController.class
 @Software:IntelliJ IDEA
*/

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.search.entity.SpuEntity;
import cn.tedu.mall.pojo.search.entity.SpuForElastic;
import cn.tedu.mall.search.service.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/search")
@Api(tags = "搜索模块")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    // 搜索模块最核心的功能就是搜索
    // 路径尽可以短
    // 所以GetMapping可以不写任何内容
    // 路径就是控制器类上面的定义的内容：localhost:10008/search
    @GetMapping
    @ApiOperation("根据用户输入关键字分页查询商品spu")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "搜索关键字", name = "keyword", dataType = "string"),
            @ApiImplicitParam(value = "页码", name = "page", dataType = "int"),
            @ApiImplicitParam(value = "条数", name = "pageSize", dataType = "int")
    })
    public JsonResult<JsonPage<SpuEntity>> searchByKeyword(String keyword, Integer page , Integer pageSize){
        JsonPage<SpuEntity> list = searchService.search(keyword,page,pageSize);
        return JsonResult.ok(list);

    }
}
